<?php

namespace App\Http\Requests\Api;

class UserRequest extends FormRequest
{
    public function rules()
    {
        switch($this->method()) {
            case 'POST':
                return [
                    'verification_key' => 'required|string',
                    'verification_code' => 'required|string|min:6',
                ];
                break;
            case 'PATCH':
                return [
                    'nickname' => 'string',
                    'realname' => 'string',
                    'introduction' => 'max:80',
                    'phone' => 'regex:/^1[34578]\d{9}$/',
                    'remark' => 'string',
                    'address' => 'string',
                    'avatar' => 'string',
                ];
                break;
        }
    }

    public function attributes()
    {
        return [
            'verification_key' => '短信验证码 key',
            'verification_code' => '短信验证码',
            'introduction' => '简介',
        ];
    }

    public function messages()
    {
        return [
            'introduction.max' => '用户简介做多可以 80 个字符。',
        ];
    }
}
